package hadoop.mapreduce.wordcountcombiner;


import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;

/**
 * 这里的输入拿到的是WordcountCombiner.class合并后的输出
 * 输入模板{a,2} {b,1} {c,2}
 */
public class WordCountReducer extends Reducer<Text, IntWritable,Text,IntWritable> {


    @Override
    protected void reduce(Text key, Iterable<IntWritable> values, Context context) throws IOException, InterruptedException {
        int sum=0;
        for (IntWritable count : values) {
            sum+=count.get();
        }
        context.write(key,new IntWritable(sum));
    }
}
